package apiday04homework;
import collection.Point;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class SortPoint {
    public static void main(String[] args) {
        /*
        List<Point> list = new ArrayList<>();
        list.add(new Point(122, 26));
        list.add(new Point(3432, 444));
        list.add(new Point(5, 6));
        list.add(new Point(7123, 85));
        list.add(new Point(922, 10));
        System.out.println("list:"+list);

        Collections.sort(list, new Comparator<Point>() {
            @Override
            public int compare(Point o1, Point o2) {
                int len1 = (int)(Math.pow(o1.getX(),2)+Math.pow(o1.getY(),2));
                int len2 = (int)(Math.pow(o2.getX(),2)+Math.pow(o2.getY(),2));
                return len1-len2;
            }
        });
        System.out.println("list:"+list);

        Collections.sort(list,(o1,o2)->{
            int len1 = (int)(Math.pow(o1.getX(),2)+Math.pow(o1.getY(),2));
            int len2 = (int)(Math.pow(o2.getX(),2)+Math.pow(o2.getY(),2));
            return len1-len2;
        });
        System.out.println("list:"+list);

         */
        List<Point> list = new ArrayList<>();
        list.add(new Point(122, 26));
        list.add(new Point(1231, 444));
        list.add(new Point(522, 6));
        list.add(new Point(7123, 85));
        list.add(new Point(922, 10));
        System.out.println("list:"+list);
        Collections.sort(list, new Comparator<Point>() {
            @Override
            public int compare(Point o1, Point o2) {
                int len1 = (int)(Math.pow(o1.getX(),2)+Math.pow(o1.getY(),2));
                int len2 = (int)(Math.pow(o2.getX(),2)+Math.pow(o2.getY(),2));
                return len2-len1;
            }
        });
        System.out.println("list:"+list);
        Collections.sort(list,(o1,o2)->{
            int len1 = (int)(Math.pow(o1.getX(),2)+Math.pow(o1.getY(),2));
            int len2 = (int)(Math.pow(o2.getX(),2)+Math.pow(o2.getY(),2));
            return len2-len1;
        });
        System.out.println("list:"+list);
    }
}
